<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书-公告(用户)</title>
    <link rel="icon" href="/static/images/t_logo.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/lyk-global.css" />
    <link rel="stylesheet" href="/static/elementui/lib/theme-chalk/index.css">
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
    <script src="/static/js/requestApi.js" type="text/javascript"></script>
    <script src="/static/js/vue/vue.js"></script>
    <!-- 引入elementui -->
    <script src="/static/elementui/js/element.js"></script>
    <script src="/static/js/axios.min.js"></script>
    <script src="/static/js/axios-config.js"></script>
    <script src="/static/js/utilJs.js"></script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="/static/vue/components/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/static/vue/components/ueditor/ueditor.all.js"></script>
    <script src="/static/vue/components/ueditorTemplate.js"></script>
</head>
<style>
    *{
        font-size: 14px
    }
    [v-cloak] {
        display: none;
    }
    .donation:hover{
        color:#409EFF;
        text-decoration:underline;
        cursor: pointer;
    }
    .active{
        color:#409EFF;
        text-decoration:underline;
    }
    .edui-toolbar{
        display:none !important;;
    }

</style>
<body style="background-color: #fff">
<div id="app" v-cloak>
    <div class="mt-8 ml-4">
        <el-input size="small" placeholder="请输入搜索的标题" style="width:200px;" v-model="queryParam.topic"  @keyup.native.enter="getTableDataMethod(true)"></el-input>
        <el-button type="primary" size="small" class="ml-2" @click="getTableDataMethod(true)">搜索</el-button>

        <el-table :data="tableData" v-loading="tableDataLoading" class="mt-4">
            <el-table-column label="标题" width="500">
                <template slot-scope="scope">
                   <span class="copy-a" @click="showTopicContentMethod(scope.row)">{{scope.row.topic}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="publishTime" label="发布时间"></el-table-column>
        </el-table>
    </div>

    <el-pagination background layout="total,sizes,prev, pager, next" :total="tableDataPaging.total"
                   :page-sizes="[10, 20, 50]"
                   prev-text="上一页" next-text="下一页"
                   :page-size="tableDataPaging.pageSize"
                   :current-page="tableDataPaging.currentPage"
                   @current-change="tableDataPagingChange"
                   @prev-click="tableDataPagingChange" @next-click="tableDataPagingChange"
                   @size-change="tableDataPagingSizeChange"
                   style="float:right;margin-top: 40px;padding-bottom:50px;">
    </el-pagination>

    <el-dialog :title="showTopicContentDialogTitle" :visible.sync="showTopicContentDialogVisible" width="1200px" :close-on-click-modal="false" append-to-body	>
        <div>
            <div class="mt-8 ml-4">
                <ueditor-template ueditor-id="noticeContentEditor" ref="noticeContentEditorRef" :show-menus=false :show-expand-button="false" :show-full-screen="false">
                </ueditor-template>
            </div>
        </div>
        <div class="df-aic-jcc mt-9 mb-9">
            <el-button size="small" class="ml-6" @click="showTopicContentDialogVisible = false">取消</el-button>
        </div>
    </el-dialog>



</div>
</body>

<script type="text/javascript">
    const vm = new Vue({ // 配置对象 options
        // 配置选项(option)
        el: '#app', // element: 指定用vue来管理页面中的哪个标签区域
        components: {
        },
        data() {
            return {
                tableData : [],
                tableDataLoading : false,
                tableDataPaging : {
                    currentPage : 1,
                    pageSize : 10,
                    total : 0,
                },
                showTopicContentDialogVisible:false,
                showTopicContentDialogTitle:'',
                noticeContentEditor:"",
                queryParam:{
                    type:"",
                    topic:""
                },
            }
        },
        mounted() {
            let that = this;
            this.$nextTick(function () {
                let type = getQueryString("type")
                if(type){
                    this.queryParam.type = type;
                }

                this.getTableDataMethod(true);
            });
        },
        methods: {
            tableDataPagingChange(val) {
                let that = this;
                that.tableDataPaging.currentPage = val;
                that.getTableDataMethod();
            },
            tableDataPagingSizeChange(val) {
                let that = this;
                that.tableDataPaging.pageSize = val;
                that.getTableDataMethod();
            },

            //获取表格的数据
            getTableDataMethod(isChongZhi){
                let that = this;
                if (isChongZhi) {
                    this.tableDataPaging.currentPage = 1;
                }
                let queryData = {
                    type: that.queryParam.type,
                    topic: $.trim(that.queryParam.topic),
                    pageNum: this.tableDataPaging.currentPage,
                    pageSize: this.tableDataPaging.pageSize,
                    state:1
                }
                this.tableDataLoading = true;
                that.tableData = [];
                axios.post('/notice/getNoticeList', queryData)
                    .then(result => {
                        let res = result.data;
                        this.tableDataLoading = false;
                        if (res.code === 0) {
                            that.tableData = res.data.list;
                            that.tableDataPaging.total = res.data.total;
                        }
                    }).catch(error => {
                    that.$message.error("error");
                    this.tableDataLoading = false;
                })
            },

            //展示公告的内容
            showTopicContentMethod(row){
                let that = this;
                that.showTopicContentDialogVisible = true;
                this.$nextTick(function () {
                    that.showTopicContentDialogTitle = row.topic;
                    if(row){
                        let deepCopyRow = JSON.parse(JSON.stringify(row));
                        that.noticeForm = deepCopyRow;//深拷贝一下
                        setTimeout(function(){
                            that.$refs.noticeContentEditorRef.setContent(deepCopyRow.content);
                        }, 800);
                    }
                });

            },
        }
    })
</script>
</html>